package com.adou.d9.tcp4;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

public class ClentReadThread extends Thread{
    private Socket socket;

    public ClentReadThread(Socket socket){
        this.socket = socket;
    }
    @Override
    public void run() {
        try {
            while(true) {
                final InputStream is = socket.getInputStream();
                final DataInputStream dis = new DataInputStream(is);


                try {
                    String msg = dis.readUTF();
                    System.out.println(msg);

                } catch (IOException e) {
                    System.out.println("有人下限了" + socket.getRemoteSocketAddress());
                    dis.close();
                    socket.close();
                    break;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
